package a66weding.com.jiehuntong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import a66weding.com.jiehuntong.inner.OnItemClickLitener;

/**
 * Created by admin on 2016/8/6.
 */
public  abstract  class MyBaseRecleAdapter<T> extends BaseRecyclerAdapter<MyBaseRecleAdapter.ViewHolder> {
    //如果有点击事件请设置一个监听;
    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    public  Context context;
    public  List<T> data = new ArrayList<>();

    public MyBaseRecleAdapter(Context context,List<T> data){
        this.context = context;
        if (data != null) {
            this.data = data;
        }
    }
    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        ViewHolder vh = new ViewHolder(getView(parent));
        return vh;
    }


    @Override
    public int getAdapterItemCount() {
        return 6;
    }

    public  class ViewHolder extends RecyclerView.ViewHolder{

        public ViewHolder(View itemView) {
            super(itemView);
            findView(itemView);
        }
    }

    public  abstract void  findView(View view);

    public abstract View  getView(ViewGroup parent);

    public void append(List<T> list) {
        if (this.data != null) {
            this.data.addAll(list);
        } else {
            this.data = list;
        }
        notifyDataSetChanged();
    }
    public void clear() {
        if (data != null) {
            this.data.clear();
        }
    }
}
